/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * fmrCursos.java
 *
 * Created on 29/10/2009, 02:31:05 PM
 */
package GUI;

import DATA.handBD;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;

/**
 *
 * @author cesar
 */
public class fmrCursos extends javax.swing.JPanel {

    /** Creates new form fmrCursos */
    public fmrCursos() {
        initComponents();
        try {
            final handBD db = new handBD();
            String[] a = new String[4];
            a[0] = "hola";


            ArrayList<String> curso = db.getCurso();
            for (int i = 0; i < curso.size(); i++) {
                listacursos.addItem(curso.get(i));
            }

            //mostrarlista.setListData(a);

            final ArrayList<String> temp = new ArrayList<String>();
            elegir.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    temp.add((String) listacursos.getSelectedItem());
                    mostrarlista.setListData(temp.toArray());
                }
            });
            matricular.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    final ArrayList<String> temp1 = new ArrayList<String>();
                    Object[] tu = temp1.toArray();
                    tu = mostrarlista.getSelectedValues();
                   try {
                        for (int i = 0; i < temp1.size(); i++)
                        {
                            //(String)(tu[i]) = temp1.get(i);
                            db.guardarmatricula((String)(tu[0]));
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(fmrCursos.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
                );
        }
            catch (Exception ex) {
        }
    }

    public JButton getEquivalentes() {
        return Equivalentes;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        academicPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("academicPU").createEntityManager();
        cursoQuery = java.beans.Beans.isDesignTime() ? null : academicPUEntityManager.createQuery("SELECT c FROM Curso c");
        cursoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : cursoQuery.getResultList();
        cursoQuery1 = java.beans.Beans.isDesignTime() ? null : academicPUEntityManager.createQuery("SELECT c FROM Curso c");
        cursoList1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : cursoQuery1.getResultList();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        mostrarlista = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        elegir = new javax.swing.JButton();
        Equivalentes = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        matricular = new javax.swing.JButton();
        listacursos = new javax.swing.JComboBox();

        jLabel1.setText("Cursos");

        jScrollPane1.setViewportView(mostrarlista);

        jButton1.setText("Seleccionar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        elegir.setText("Elegir");

        Equivalentes.setText("Equivalentes");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"
            }
        ));
        jScrollPane3.setViewportView(jTable1);

        jLabel2.setText("HORARIO DE CLASES");

        matricular.setText("Matricular");
        matricular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                matricularActionPerformed(evt);
            }
        });

        listacursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listacursosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel1)
                        .addGap(105, 105, 105)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(listacursos, 0, 213, Short.MAX_VALUE)))
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(elegir)
                    .addComponent(matricular)
                    .addComponent(Equivalentes))
                .addGap(63, 63, 63))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 541, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(90, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Equivalentes)
                            .addComponent(listacursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(elegir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(matricular)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void matricularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_matricularActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_matricularActionPerformed

    private void listacursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listacursosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_listacursosActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Equivalentes;
    private javax.persistence.EntityManager academicPUEntityManager;
    private java.util.List<GUI.Curso> cursoList;
    private java.util.List<GUI.Curso> cursoList1;
    private javax.persistence.Query cursoQuery;
    private javax.persistence.Query cursoQuery1;
    private javax.swing.JButton elegir;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JComboBox listacursos;
    private javax.swing.JButton matricular;
    private javax.swing.JList mostrarlista;
    // End of variables declaration//GEN-END:variables
}
